<template>
	<view>
		<Chat ref="mescrollItem0" :i="0" :index="tabIndex" :topXp="topXp" :dialog_ident="ident" :appid="appid" :fabu="fabu" :welcome_message="welcome_message" v-if="ident" :askQuestions='askQuestions' ></Chat>
	</view>
</template>

<script>
	import MescrollMoreMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more.js";
	import Chat from '@/components/chat/chat.vue'
	import http from '@/api/api-index.js'
	
	export default{
		mixins: [MescrollMoreMixin], // 使用mixin
		components:{
			Chat,
		},
		data(){
			return{
				tabIndex:0,
				topXp:0,
				ident:'',//对话标识
				appid:'',//助手ID
				user_id:'',
				welcome_message:'',
				askQuestions:[],//推荐问题
				fabu:false,//发布标识
			}
		},
		onLoad(options) {
			this.user_id = uni.getStorageSync('uid')
			if(!this.user_id){
				uni.showModal({
					title: '提示',
					content: '暂无登录，请前去登录',
					success: function (res) {
						if (res.confirm) {
							uni.navigateTo({
								url:'/pages/login/login'
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}else{
				// console.log(options)
				this.ident = options.ident
				this.appid = options.appid
				this.fabu = options.fabu
				this.welcome_message = options.welcome_message
				this.askQuestions = JSON.parse( options.askQuestions)
				if(this.appid){
					http.postCreateChat({
						user_id:this.user_id,
						appid:this.appid
					}).then((res)=>{
						this.ident = res.data.result
					})
				}
				uni.setNavigationBarTitle({
					title: options.name
				});
			}
			
			// console.log(this.ident)
		},
		methods:{
			
		}
	}
</script>